package com.examplemartin.jpademo.pojo.po.sell;

import com.examplemartin.jpademo.annotation.EntityCheck;
import com.examplemartin.jpademo.pojo.admin.BaseEntity;
import com.examplemartin.jpademo.pojo.po.UserPO;
import com.examplemartin.jpademo.pojo.po.cust.CustPO;
import com.examplemartin.jpademo.pojo.po.repository.sell.SellOutPO;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 销售订单实体
 */

@Data
@EqualsAndHashCode(callSuper = true)
@Entity(name = "t_sell")
public class SellPO extends BaseEntity implements Serializable {

  public static Integer SELL_STATUS_SPARE = 0;
  public static Integer SELL_STATUS_WAIT = 1;
  public static Integer SELL_STATUS_RUNNING = 2;
  public static Integer SELL_STATUS_FINISH = 3;
  public static Integer SELL_STATUS_DISABLE = 4;
  public static String SELL_STATUS_SPARE_NAME = "编制...";
  public static String SELL_STATUS_WAIT_NAME = "等待...";
  public static String SELL_STATUS_RUNNING_NAME = "编制...";
  public static String SELL_STATUS_FINISH_NAME = "结束...";
  public static String SELL_STATUS_DISABLE_NAME = "失效...";
  public static ArrayList<String> PURPO_STATUS_NAME = new ArrayList<String>(
      (Arrays.asList(SELL_STATUS_SPARE_NAME,
          SELL_STATUS_WAIT_NAME,
          SELL_STATUS_RUNNING_NAME,
          SELL_STATUS_FINISH_NAME,
          SELL_STATUS_DISABLE_NAME)));
  public static ArrayList<Integer> PURPO_STATUS_VALUE = new ArrayList<Integer>(
      (Arrays.asList(SELL_STATUS_SPARE,
          SELL_STATUS_WAIT,
          SELL_STATUS_RUNNING,
          SELL_STATUS_FINISH,
          SELL_STATUS_DISABLE)));
  // 对应销售员 one
  @ManyToOne
  private UserPO userPO;
  // 销售缺货单 one
  @JsonIgnore
  @OneToMany(mappedBy = "sellPO")
  private List<ShortPO> shortPOList;
  // 客户 one
  @ManyToOne
  private CustPO custPO;
  // 销售单明细 list
//  @JsonIgnore
  @OneToMany(mappedBy = "sellPO")
  private List<SellDetailPO> sellDetailPOList;

  // 销售出库单 list
//  @JsonIgnore
  @OneToMany(mappedBy = "sellPO")
  private List<SellOutPO> sellOutPOList;

  // 订单好
  @EntityCheck(required = true, errRequired = "必须输入订单号")
  private String name;

  // 要货日期
  private Date need;

  // 订单状态
  private Integer status = SELL_STATUS_SPARE;

  private String comment;

  @Override
  public String toString() {
    return "SellPO{" +
            "userPO=" + userPO +
            ", custPO=" + custPO +
            ", name='" + name + '\'' +
            ", need=" + need +
            ", status=" + status +
            ", comment='" + comment + '\'' +
            '}';
  }
}
